package com.innovation.chengzhangriji.ui.widget;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by lichuanzhi on 2015/11/26.
 */
public class CommentItemDecoration extends RecyclerView.ItemDecoration {

    private Paint paintLine;

    public CommentItemDecoration() {
        paintLine = new Paint();
        paintLine.setColor(Color.rgb(224, 224, 224));
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
        final int childCount = parent.getChildCount();
        if(childCount > 0) {
            if(childCount == 1 && parent.getAdapter().getItemViewType(childCount - 1) == DiscoverCommentAdapter.LOAD_MORE) {
                return;
            }
            int count = childCount;
            if(parent.getAdapter().getItemViewType(childCount - 1) == DiscoverCommentAdapter.LOAD_MORE) {
                count -= 1;
            }
            for (int i = 0; i < count; i++) {
                final View child = parent.getChildAt(i);
                c.drawRect(child.getLeft(), child.getBottom(), child.getRight(), child.getBottom() + 1 * parent.getContext().getResources().getDisplayMetrics().density, paintLine);
            }
        }
    }
}
